import { createVNode, render } from 'vue'
import Loading from '@/components/Loading.vue'

let loadingInstance = null

export const createLoading = () => {
  if (!loadingInstance) {
    // 创建容器
    const container = document.createElement('div')
    // 创建虚拟节点
    const vnode = createVNode(Loading)
    // 渲染到容器
    render(vnode, container)
    // 添加到 body
    document.body.appendChild(container)
    // 保存实例
    loadingInstance = vnode.component
  }
  return loadingInstance.exposed
} 